/* $Id: listtable.js 14980 2008-10-22 05:01:19Z testyang $ */


var url = "flow.php?step=done";
var order = new Object;


order.Info = new Object;
order.Info.AddressId;
order.Info.Message;
order.Info.PayId = 1;
order.Info.CouponId;
order.Info.Rid;
    
/*提交订单*/
order.SumbitOrder = function()
{

    if (!isNull(order.Info.PayId)) {
        order.Info.PayId=$(".payment:checked").val();
    };
    if (!isNull(order.Info.Message)) {
        order.Info.Message=$("#postscript").val();
    };
    $.post(url, {'order' : order.Info},
    this.ReturnOrder
    ,'JSON');
}

/*订单提交回调*/
order.ReturnOrder = function  (data) {
    /*提交失败时提示错误*/
    if (data.error > 0 && data.error != 602) {
        point(data.message,1);
        return false;
    };
    /*库存不足提示*/
    if ( data.error === 602) {
        prompt(data.message,"location.href='flow.php';");
         return false;
    };
    /*货到付款提交成功*/
    if (data.content.payId === 3) {
        window.location.href='flow.php?step=complete&order_id='+data.content.orderId;
    }
    /*支付宝提交成功*/
    if (data.content.payId === 1) {
        window.location.href='flow.php?step=complete&order_id='+data.content.orderId;
    }
}


/*计算订单费用*/
order.Cost = function (){
    point('计算中..');
    $.post('flow.php?step=select_coupon', {'order' : order.Info},
    this.ReturnCost
    ,'JSON');

}

/*计算订单费用*/
order.ReturnCost = function (data){
    if (data.error>0) {
        point(data.message);
    }
    else{
        $("#point").remove();
        $('#shipping_fee').html(data.content.shipping_fee_formated);
        $('#goods_price').html(data.content.goods_price_formated);
        $('#amount_formated').html(data.content.amount_formated);
        $('#amount').html(data.content.amount_formated);
    };
}

function isNull(data){
return (data == "" || data == undefined || data == null) ? false : true; 
}


